<%@page import="java.io.File"%>
<%@page import="java.io.OutputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.IOException"%>
<%@page import="java.net.URLConnection"%>
<%@page import="java.net.URL"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%
String pdfurl = request.getParameter("pdf_url");
OutputStream  o = null;
InputStream in = null;
if(pdfurl!=null && !"".equals(pdfurl)){
	System.out.println("查看PDF : "+pdfurl);
	try {   
	    URL url = new URL(pdfurl);   
	    URLConnection conn = url.openConnection();   
	    in = conn.getInputStream();
	    o = response.getOutputStream();
	    int index = 0;
	    byte buffer[] = new byte[1024];
	     while ((index = in.read(buffer)) != -1) {
	    	 o.write(buffer , 0, index);
	     }
	     out.clear(); 
	     out=pageContext.pushBody();
	     o.close();
	     in.close();
	} catch (Exception e) {   
		 System.out.println("查看PDF -- ERROR : "+e);
		 o.close();
		 in.close();
	} 
}else{
	System.out.println("缺少pdf_url参数 ，打开默认pdf文件 ：helloworld.pdf");
	try {   
	    String pdfPath = request.getSession().getServletContext().getRealPath("web")+"/helloworld.pdf"; 
	    File f = new File(pdfPath);
	    in = new FileInputStream(f);
	    o = response.getOutputStream();
	    int index = 0;
	    byte buffer[] = new byte[1024];
	     while ((index = in.read(buffer)) != -1) {
	    	 o.write(buffer , 0, index);
	     }
	     out.clear(); 
	     out=pageContext.pushBody();
	     o.close();
	     in.close();
	} catch (Exception e) {   
		 System.out.println("查看PDF -- ERROR : "+e);
		 o.close();
		 in.close();
	} 
}
     
%>